/*
 * Created by Jesse Phillips
 * Created on Feb 25, 2006
 */

/**
 * Stack implemented using an array.
 */
public class ArrayStack {
	private int index;
	private char[] stack;
	
	public ArrayStack(int size) {
		stack = new char[size];
		index = size;
	}

	/**
	 * Add an item to the stack
	 * 
	 * @param item what is to be stored
	 */
	public void push(char item) {
/*ans bl*/
		if(!isFull())
			stack[--index] = item;
/*ans ab*/
	}
	
	/**
	 * Return an item off the top of the stack.
	 * 
	 * @return the item in the stack
	 */
	public char pop() {
/*ans bl*/
		if(!isEmpty())
			return stack[index++];
		return 0;
/*ans ab*/
	}

	/**
	 * Checks to see if there is room in the stack
	 * 
	 * @return true if the stack is full
	 */
	public boolean isFull() {
		if(index == 0)
			return true;
		else
			return false;
	}
	
	/**
	 * Checks the emptiness of the stack
	 * 
	 * @return true if the stack is empty
	 */
	public boolean isEmpty() {
		if(index == stack.length)
			return true;
		else
			return false;
	}
	
	/**
	 * Returns the top item in the stack but does not
	 * remove it.
	 * 
	 * @return the item on top of the stack
	 */
	public char peak() {
		return stack[index];
	}
}
